package ilearn.job.ilearnjobgrayversionjava17.buss.config;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Log4j2
@Configuration
public class GrayVersionConfig {

    @Bean
    public ReactorServiceInstanceLoadBalancer myGayVersionLoadBlancerClient(Environment environment,
            ObjectProvider<ServiceInstanceListSupplier> provider){
        String serviceId = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
        log.info("负载均衡器准备创建，目标服务： {}",serviceId);
        return new GrayVersionLoadBlancerClient(serviceId,provider);
    }
}
